function SelectTag(t) {
    this.child = t.child || ".default",
        this.over = t.over || "on",
        this.all = t.all || ".all",
        this.init()
}
$.extend(SelectTag.prototype, {
    init: function() {
        var t = this;
        t._bindEvent(), t._selectEvent();
    },
    _GetRequest: function() {
        var url = window.location.search;
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1).split("&");
            str.forEach(item => {
                theRequest[item.split("=")[0]] = decodeURIComponent(item.split("=")[1]);
            });
        }
        return theRequest;
    },
    _bindEvent: function() {
        var t = this;
        $(t.child).click(function(e) {
            e.preventDefault();
            var n = $(this).attr("name");
            $(this).hasClass(t.over) || ($("[name=" + n + "]").removeClass(t.over), $(this).addClass(t.over)
            , window.location.href = t._changeURLParams(n, $(this).attr("rel")));
        }), $(t.all).click(function(e) {
            e.preventDefault();
            var n = $(this).attr("name");
            $(this).hasClass(t.over) || ($("[name=" + n + "]").removeClass(t.over), $(this).addClass(t.over)
            , window.location.href = t._delUrlParams(n));
        })
    },
    _selectEvent: function() {
        var t = this, urlObj = t._GetRequest();
        $(t.child).each(function() {
            var hasValue = false;
            var name = $(this).attr("name");
            var value = $(this).attr("rel");            
            if(urlObj.hasOwnProperty(name))hasValue = urlObj[name] == value;
            if (hasValue) {
                $(this).addClass(t.over);
                $("[name=" + name + "]").eq(0).removeClass(t.over);
            } else {
                $(this).removeClass(t.over);
            }
        })
    },
    _delUrlParams: function(name) {
        var urlObj = this._GetRequest();
        if(name && urlObj.hasOwnProperty(name)){
            delete urlObj[name];
        }
        if($.isEmptyObject(urlObj)){
            return "./";
        }
        var params = new URLSearchParams(urlObj);
        return "?" + params.toString();
    },
    _changeURLParams: function(name, value) {
        var urlObj = this._GetRequest();
        if(name)urlObj[name] = value;
        var params = new URLSearchParams(urlObj);
        return "?" + params.toString();
    }
});

/*
<dl class="cation-list">
    <dt>类别</dt>
    <dd>
        <a rel="" name="cid" class="all on">全部</a>
        <a rel="35" name="cid" class="default">Unit 1&2</a>
    </dd>
</dl>
<script>
    (function (callback) {
        require.callback = function () {
            callback && callback.call();
            require(['jquery'], function ($) {
                require(['/assets/js/selecttag/current.js'], function (undefined) {
                    new SelectTag({child:".default",over:'on',all:".all"});
                });
            });
        };
    })(require.callback);
</script>
*/